﻿@using System.Web.UI.WebControls
@using WindMill.Models.Estoque
@model LookupField.Models.LookupModel
<div class="col-xs-2">
    <label class="control-label" for="@Model.FieldId">@Model.FieldDescription</label>
    <input id="@Model.FieldId" type="text" value="@Model.Value" lookup-url="@Model.LookupUrl" class="form-control input-sm lookup-field" />
    @Html.ValidationMessageFor(model => model)    
</div>                      
<div class="col-xs-8">
    <label class="control-label">&nbsp;</label>                    
    <div class="input-group">
        <span  id="@Model.FieldId-search" class="input-group-addon" ><i class="icon-search"></i></span>    
        <span  id="@Model.FieldId-create" class="input-group-addon" ><i class="icon-plus"></i></span>                    
        <input id="@Model.FieldId-description" type="text" class="form-control input-sm" value="" disabled="disabled" />
    </div>                    
</div>          

<div id="@Model.FieldId-dialog" title="Procurar @Model.FieldDescription" style="display:none;">    
    <script>
        jQuery(document).ready(function() {
            $("#@Model.FieldId-search").click(function() {
                $("#@Model.FieldId-dialog").dialog({
                            resizable: false,
                            width: $(window).width() * 0.8,
                            height: $(window).height() * 0.7,
                            modal: false,
                            show: {
                                effect: 'blind',
                            },
                            open: function () {
                                if($('#@Model.FieldId-dialog').attr("initialized")!= 'true')
                                    $("#@Model.FieldId-dialog").load("@Model.SearchView .datatables", function() {
                                        var table = $('#@Model.FieldId-dialog .datatables').configTables(function() {
                                            
                                            $("#@Model.FieldId-dialog .datatables tbody tr").dblclick(function (e) {
                                                var data = table.fnGetData(this);
                                                //var campo = "@Model.FieldId";
                                                var campo = "CodClasse";
                                                $("#@Model.FieldId").val(data[campo]);
                                                $("#@Model.FieldId").blur();
                                                $("#@Model.FieldId-dialog").dialog("close");
                                            });
                                            

                                        });
                                        $('#@Model.FieldId-dialog').attr("initialized", 'true');
                                        
                                        
                                            
                                      
                                    });
                            }
                        });
            });
            
        });
    </script>    
</div>